package com.mt.lulucai.widget;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.mt.lulucai.R;


/**
 * Created by daiguangtao on 2020/11/07.
 */

public class TipsDialog extends DialogFragment implements View.OnClickListener {


    Button mBtnConfirm;
    TextView mTitle;
    TextView mContent;

    TipsListener mTipsListener;

    public static TipsDialog getInstance() {
        TipsDialog loadingDialog = new TipsDialog();
        return loadingDialog;
    }
    public static TipsDialog getInstance(String title,String msg) {
        TipsDialog loadingDialog = new TipsDialog();
        Bundle bundle = new Bundle();
        bundle.putString("TITLE", title);
        bundle.putString("CONTENT", msg);
        loadingDialog.setArguments(bundle);
        return loadingDialog;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        getDialog().setCancelable(false);
        View view = inflater.inflate(R.layout.dialog_tips, container);
        initView(view);
        Bundle bundle = getArguments();
        String title = bundle.getString("TITLE");
        String content = bundle.getString("CONTENT");
        if(title !=null && !"".equals(title)){
            mTitle.setText(title);
        }
        if(content !=null && !"".equals(content)){
            mContent.setText(content);
        }
        mBtnConfirm.setOnClickListener(this);
        return view;
    }
    public void initView(View view){
        mBtnConfirm = view.findViewById(R.id.btn_confirm);
        mTitle = view.findViewById(R.id.title);
        mContent = view.findViewById(R.id.tv_content);
    }
    public void setListener(TipsListener listener) {
        mTipsListener = listener;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_confirm:
                if (mTipsListener!=null){
                    mTipsListener.onConfirm();
                }
                dismiss();
                break;
        }
    }

    public static interface TipsListener {
        void onConfirm();
    }
}
